/*=+--+=#=+--     Unmanned Aerial System Management Software      --+=#=+--+=#*\
|          Copyright (C) 2011 Regents of the University of Colorado.           |
|                             All Rights Reserved.                             |

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

            Jack Elston                       Cory Dixon                        
|           elstonj@colorado.edu              dixonc@colorado.edu              |
|                                                                              |
\*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*/


#ifndef __DMSIM_H
#define __DMSIM_H

#include "threadedPipe.h"

#define UPDATE_PERIOD   (1)  // in seconds (unused right now)
#define MAX_CONNECTIONS (128)


// these define the wing mappings
const uint16_t dm_on_map[NUM_DEPLOY_MECHANISMS] = {
  0x0009,
  0x0011,
  0x0012,
  0x0022,
  0x0024,

  0x0240,
  0x0440,
  0x0480,
  0x0880,
  0x0900
};

#define OFF_STATE       (0x0e38)
#define MEASURED_STATE  (0x0e3c)


class DMSim : public ThreadedPipe
{
  private:
    // TCP server components
    int client_fds[MAX_CONNECTIONS];
    int num_connections;
    int port;

    Mothership_t mothership;
    uint16_t status;

    void publishSim();
    void publish(in_addr_t *dest);

    bool validRead();

    static void* tcpServer(void *data);

  public:
    DMSim(String name, int port=1234);
    ~DMSim() {}

    bool init(ShmStruct * shmStructPtr);
    void update();

    int random_set();
    void hexDump(char *buf, int len);
};

#endif
